package com.marktotop.controller.business;


import com.marktotop.dto.GetVaccineHistoryDTO;
import com.marktotop.entity.business.VaccineHistory;
import com.marktotop.error.SystemException;
import com.marktotop.response.ResultBean;
import com.marktotop.service.IVaccineHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.sql.ResultSet;

/**
 * <p>
 *  前端控制器 - 疫苗历史
 * </p>
 *
 * @author MarkToTop
 * @since 2021-07-12
 */
@Api(tags = "业务模块-疫苗历史接口")
@RestController
@RequestMapping("/business/history")
public class VaccineHistoryController {

    @Autowired
    private IVaccineHistoryService historyService;


    /**
     * 判断是否有无疫苗历史记录
     *
     * @param historyDTO
     * @return
     * @throws SystemException
     */
    @ApiOperation(value = "注射疫苗记录", notes = "判断接种人是否注射过该疫苗的第几针")
    @RequestMapping(value = "/findRecord",method = RequestMethod.GET)
    public ResultBean findVaccineRecord(@RequestBody GetVaccineHistoryDTO historyDTO) throws SystemException {
        Long vaccineId = historyDTO.getVaccineId();
        Long vaccinatorId = historyDTO.getVaccinatorId();
        if (!historyService.haveVaccineRecord(vaccinatorId, vaccineId)){
            return ResultBean.error().message("没有该疫苗的接种记录!");
        }
        return ResultBean.ok().message("有该疫苗的接种记录！");
    }

}
